package com.example.tangjiangxu.lifecycle;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.example.tangjiangxu.lifecycle.flags.FlagsActivity;
import com.example.tangjiangxu.lifecycle.launchmode.LaunchModeActivity;
import com.example.tangjiangxu.lifecycle.lifecycle.LifecycleActivity;

public class MainActivity extends Activity {
    private final static String TAG = "LaunchModeActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn_lifecycle).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, LifecycleActivity.class);
                startActivity(intent);
            }
        });

        findViewById(R.id.btn_launchmode).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, LaunchModeActivity.class);
                startActivity(intent);
            }
        });
        findViewById(R.id.btn_flag).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, FlagsActivity.class);
                startActivity(intent);
            }
        });

        findViewById(R.id.btn_intentfilter).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction("com.josan");
                intent.addCategory("com.tang");
                intent.setDataAndType(Uri.parse("http://josan.com"), null);
                //检查是否有匹配规则的Activity
                /*if (MainActivity.this.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
                    startActivity(intent);
                }*/
                /*if (MainActivity.this.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0) {
                    startActivity(intent);
                }*/
                if (intent.resolveActivity(MainActivity.this.getPackageManager()) != null) {
                    startActivity(intent);
                }
            }
        });
    }
}
